package com.mvc.controller;

import com.alibaba.fastjson.JSON;
import com.mvc.entity.HomeLbt;
import com.mvc.model.Result;
import com.mvc.service.LbtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName LbtController
 * @Description TODO
 * @Author Roc
 * @Date 2021/11/27 16:30
 * @Version 1.0
 **/
@Controller
@RequestMapping(value = "/lbt", produces = "text/html;charset=UTF-8")
public class LbtController {

    @Autowired
    private LbtService lbtService;

    @RequestMapping(value = "/all.do")
    @ResponseBody
    public String listAll(HomeLbt homeLbt
                          ){

        List<HomeLbt> list = lbtService.listAll(homeLbt);
        Result result = new Result();
        result.setCode(0);
        result.setData(list);
        String json = JSON.toJSONString(result);
        return json;
    }

    @RequestMapping(value = "/insert.do")
    @ResponseBody
    public String add(HomeLbt homeLbt){
        Integer n = lbtService.insert(homeLbt);
        Result result = new Result();
        if (n == 1){
            result.setCode(0);
            result.setMsg("成功");
        }else {
            result.setCode(1);
            result.setMsg("失败");
        }
        String json = JSON.toJSONString(result);
        return json;

    }

    @RequestMapping(value = "/update.do")
    @ResponseBody
    public String update(HomeLbt homeLbt){
        Integer n = lbtService.update(homeLbt);
        Result result = new Result();
        if (n == 1){
            result.setCode(0);
            result.setMsg("成功");
        }else {
            result.setCode(1);
            result.setMsg("失败");
        }
        String json = JSON.toJSONString(result);
        return json;

    }

    @RequestMapping(value = "/del.do")
    @ResponseBody
    public String del(@RequestParam Integer id){
        Integer n = lbtService.del(id);
        Result result = new Result();
        if (n == 1){
            result.setCode(0);
            result.setMsg("成功");
        }else {
            result.setCode(1);
            result.setMsg("失败");
        }
        String json = JSON.toJSONString(result);
        return json;

    }




}
